package com.cloudlead.common.lang.serialize;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import com.cloudlead.common.lang.utils.DateTimeConvertUtils;

/**
 * 自定义日期序列化格式
 * 
 * @author dean.lu
 * 
 */
public class DateAdapter extends XmlAdapter<String, Date> {
	private SimpleDateFormat dateFormat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	@Override
	public String marshal(Date v) throws Exception {
		return dateFormat.format(v);
	}

	@Override
	public Date unmarshal(String v) throws Exception {
		return DateTimeConvertUtils.convertToDate(v);
	}
}
